﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Financial_FinanceAuditHandler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["OrderID"] != null)
        {
            if (Request.QueryString["OrderID"].Trim().Length == 10)
            {
                var orderID = Request.QueryString["OrderID"].Trim();

                Label3.Text = orderID;

                var order = new OrderBLL().GetOrderInfoByOrderID(orderID);
                if (order != null)
                {
                    var empolyeeID = order.EmpolyeeID;
                    var empolyeeName = new EmpolyeeBLL().GetEmpolyeeNameByEmpolyeeID(empolyeeID);
                    Label4.Text = empolyeeName;

                    Label1.Text = order.Amount.ToString();
                    Label2.Text = RemarkAttribute.GetEnumRemark(order.CurrencyType);
                    Label5.Text = new OrderBLL().GetIncomeByOrderID(orderID).ToString();

                    if (Label5.Text.Equals(Label1.Text))
                    {
                        Label6.Text = "平";
                        Label6.ForeColor = System.Drawing.Color.Green;
                        Button1.Enabled = true;
                    }
                    else
                    {
                        Label6.Text = "不平";
                        Label6.ForeColor = System.Drawing.Color.Red;
                        Button1.Enabled = false;
                    }
                }

            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        // 转入分行快递，发送给客户
        if (Request.QueryString["OrderID"] != null)
        {
            if (Request.QueryString["OrderID"].Trim().Length == 10)
            {
                var orderID = Request.QueryString["OrderID"].Trim();

                // 写入订单轨迹
                var empolyeeID = new EmpolyeeBLL().GetEmpolyeeInfoByLoginName(User.Identity.Name).EmpolyeeID;
                new OrderTrackBLL().AddTrack(orderID, empolyeeID, Koonsoft.HYCRM.Model.OrderStatus.FinanceAudit, 1, Remark.Text.Trim());

                // 通知订单状态改变
                new OrderBLL().ChangeOrderStatusByOrderID(orderID, Koonsoft.HYCRM.Model.OrderStatus.BranchDeliver);

                Response.Redirect("OrdersForFinanceAudit.aspx");
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        // 应收款不平，回分行财务督促收款
        if (Request.QueryString["OrderID"] != null)
        {
            if (Request.QueryString["OrderID"].Trim().Length == 10)
            {
                var orderID = Request.QueryString["OrderID"].Trim();

                // 写入订单轨迹
                var empolyeeID = new EmpolyeeBLL().GetEmpolyeeInfoByLoginName(User.Identity.Name).EmpolyeeID;
                new OrderTrackBLL().AddTrack(orderID, empolyeeID, Koonsoft.HYCRM.Model.OrderStatus.FinanceAudit, 1, Remark.Text.Trim());

                // 通知订单状态改变
                new OrderBLL().ChangeOrderStatusByOrderID(orderID, Koonsoft.HYCRM.Model.OrderStatus.BranchAccountant);

                Response.Redirect("OrdersForFinanceAudit.aspx");
            }
        }

    }
}